package top.kaoshanji.p2ch09a;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * 代码清单-p2ch09a-299页a：Class.forName方法与ClassLoader类在加载类时的不同之处
 * author kaoshanji
 * ^_^
 * create time 2025/2/2 13:39
 */
public class ClassForNameMain {

    private static final Logger logger = LogManager.getLogger(ClassForNameMain.class);

    public static void main(String[] args) {

        logger.info("...代码清单-p2ch09a-299页a：Class.forName方法与ClassLoader类在加载类时的不同之处...");

        ClassForNameMain main = new ClassForNameMain();
        try {
            main.classForNameVsLoader();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }


    public void classForNameVsLoader() throws ClassNotFoundException {

        String className = "top.kaoshanji.p2ch09a.ClassForNameTest";
        // 有输出
        Class<?> clazz1 = Class.forName(className);

        ClassLoader loader = this.getClass().getClassLoader();
        // 没有输出
        Class<?> clazz2 = loader.loadClass(className);

    }

}
